﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="SaleInvoiceEdit.aspx.cs"
    Inherits="Main_ServiceInvoice_SaleInvoiceEdit" Culture="en-GB" %>

<%@ Register Src="~/User Controls/PageHeading.ascx" TagName="heading" TagPrefix="acc" %>
<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="AjaxControl" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>Edit Sale Invoice</title>
    <link href="../../Styles/accounts.css" rel="stylesheet" type="text/css" />

    <script type="text/javascript">

        function isNumberKey(control_id, evt) {
            var charCode = (evt.which) ? evt.which : event.keyCode
            if (charCode > 31 && (charCode < 48 || charCode > 57) && (charCode < 45 || charCode > 47))
                return false;

            if (charCode == 46) {
                var dotcount = document.getElementById(control_id).value.split('.').length - 1;
                if (dotcount >= 1) {
                    return false;
                }
            }
            return true;
        }

        function EnabledTabKey(id, e) {
            var keycode;
            if (window.event) {
                keycode = window.event.keyCode;
            }
            else if (e) {
                keycode = e.which;
            }
            else {
                return true;
            }

            if (keycode == 9) {
                // if is the tab key                
                return true;
            }
            else {
                return false;
            }
        }
        function GetLastNumber(str) {
            for (var i = 0; i < str.length; i++) {
                if (!isNaN(str.charAt(i))) {
                    str = str.substring(str.indexOf(str.charAt(i)));
                    break;
                }
            }
            var rgx = new RegExp("[a-zA-Z]");
            if (rgx.test(str)) {
                str = str.substring(1);
                return (GetLastNumber(str));
            }
            else {
                return str;
            }
        }
        function ValidateRequired(id) {
            var lastno = GetLastNumber(id);
            var ddl = document.getElementById(id);
            var flag = true;
            if (document.getElementById("ddlCustomer").value == '0') {
                alert('Select Customer First!');
                document.getElementById("ddlCustomer").focus();
                flag = false;
                ddl.value = '0';
            }
            else if (document.getElementById("txtrefno").value == '') {
                alert('Enter Ref No.');
                document.getElementById("txtrefno").focus();
                flag = false;
                ddl.value = '0';
            }
            else if (document.getElementById("txtdate").value == '') {
                alert('Enter Date');
                document.getElementById("txtdate").focus();
                flag = false;
                ddl.value = '0';
            }
            setTimeout('__doPostBack(\'' + id + '\',\'\')', 0);

            return flag;
        }

        function clearfields() {
            if (document.getElementById("txttaxableamount") != null) {
                document.getElementById("txttaxableamount").value = '0';
            }
            if (document.getElementById("txtdiscounttaxamt") != null) {
                document.getElementById("txtdiscounttaxamt").value = '0';
            }
            if (document.getElementById("txtdiscounttaxper") != null) {
                document.getElementById("txtdiscounttaxper").value = '0';
            }
            if (document.getElementById("txtnontaxableamount") != null) {
                document.getElementById("txtnontaxableamount").value = '0';
            }
            if (document.getElementById("txtnondiscounttaxamt") != null) {
                document.getElementById("txtnondiscounttaxamt").value = '0';
            }
            if (document.getElementById("txtnondiscounttaxper") != null) {
                document.getElementById("txtnondiscounttaxper").value = '0';
            }
            if (document.getElementById("txtservicechargeamt") != null) {
                document.getElementById("txtservicechargeamt").value = '0';
            }
            if (document.getElementById("txttotalamount") != null) {
                document.getElementById("txttotalamount").value = '0';
            }
            if (document.getElementById("txtservicetax") != null) {
                document.getElementById("txtservicetax").value = '0';
            }
            if (document.getElementById("txtpecess") != null) {
                document.getElementById("txtpecess").value = '0';
            }
            if (document.getElementById("txthecess") != null) {
                document.getElementById("txthecess").value = '0';
            }
            if (document.getElementById("txtluxuarytax") != null) {
                document.getElementById("txtluxuarytax").value = '0';
            }
            if (document.getElementById("txtroundofamt") != null) {
                document.getElementById("txtroundofamt").value = '0';
            }
            if (document.getElementById("txtgrandtotal") != null) {
                document.getElementById("txtgrandtotal").value = '0';
            }
        }
        function CalculateGrandTotal(id) {
            var lastno = GetLastNumber(id);
            var chkbx = document.getElementById("chkDelete" + lastno);
            if (chkbx.checked == true) {
                document.getElementById("txtunitrate1ctrl" + lastno).value = "0";
                document.getElementById("txtunitrate2ctrl" + lastno).value = "0";
            }
            if (document.getElementById("hidunit").value.search('u2') >= 0) {
                var unit2 = document.getElementById("txtunit2ctrl" + lastno).value;
                if (unit2 == '') {
                    unit2 = 0;
                }
                var rate = document.getElementById("txtunitrate2ctrl" + lastno).value;
                if (rate == '') {
                    rate = 0;
                    document.getElementById("txtunitrate2ctrl" + lastno).value = 0;
                }
            }
            if (document.getElementById("hidunit").value.search('u3') >= 0) {
                var unit3 = document.getElementById("txtunit3ctrl" + lastno).value;
                if (unit3 == '') {
                    unit3 = 0;
                }
                var rate = document.getElementById("txtunitrate2ctrl" + lastno).value;
                if (rate == '') {
                    rate = 0;
                    document.getElementById("txtunitrate2ctrl" + lastno).value = 0;
                }
            }
            if (document.getElementById("hidunit").value.search('u4') >= 0) {
                var unit4 = document.getElementById("txtunit4ctrl" + lastno).value;
                if (unit4 == '') {
                    unit4 = 0;
                }
                var rate = document.getElementById("txtunitrate2ctrl" + lastno).value;
                if (rate == '') {
                    rate = 0;
                    document.getElementById("txtunitrate2ctrl" + lastno).value = 0;
                }
            }

            var servicetaxper = parseFloat(document.getElementById("txtservicetaxpercent").value).toFixed(2);
            if (servicetaxper == '') {
                servicetaxper = 0;
            }
            var pecesstaxper = parseFloat(document.getElementById("txtpecesspercent").value).toFixed(2);
            if (pecesstaxper == '') {
                pecesstaxper = 0;
            }
            var hecesstaxper = parseFloat(document.getElementById("txthecesspercent").value).toFixed(2);
            if (hecesstaxper == '') {
                hecesstaxper = 0;
            }
            var luxuarytaxper = parseFloat(document.getElementById("txtluxuarytaxpercent").value).toFixed(2);
            if (luxuarytaxper == '') {
                luxuarytaxper = 0;
            }
            document.getElementById("txtserviceTax1crtl" + lastno).value = '0';
            document.getElementById("txtserviceTax2crtl" + lastno).value = '0';
            document.getElementById("txtserviceTax3crtl" + lastno).value = '0'; 
            if (document.getElementById("ddlservice" + lastno).value != "0") {

                var ServiceChargeper = Number(document.getElementById("txtservicecharge1crtl" + lastno).value);
                if (ServiceChargeper == '') {
                    ServiceChargeper = 0;
                }
                var servicechargeRate = parseFloat((parseFloat(parseFloat(ServiceChargeper) * 100) / 1000 / 10) + 1).toFixed(2);
                var ServiceTaxRate = (parseFloat(parseFloat(servicetaxper) + (parseFloat(pecesstaxper) / 10) + (parseFloat(hecesstaxper) / 10) + (parseFloat(luxuarytaxper) / 10)) * 100 / 1000 / 10) + 1;
                if (document.getElementById("hidunitrate").value == 'yes') {
                    var Ratetemp = 0;
                    var TotalUnit = Number(document.getElementById("txtunitrate1ctrl" + lastno).value);
                    var rate = 0;
                    rate = Number(document.getElementById("txtunitrate2ctrl" + lastno).value);
                    if (TotalUnit > 0) {
                        Ratetemp = parseFloat(TotalUnit) * parseFloat(rate);
                    }
                    else {
                        Ratetemp = rate;
                    }
                    if (document.getElementById("hidunit").value.search('u2') >= 0) {
                        TotalUnit = parseFloat(unit2);
                        if (TotalUnit > 0) {
                            Ratetemp = (parseFloat(Ratetemp) * parseFloat(TotalUnit));
                        }
                    }
                    if (document.getElementById("hidunit").value.search('u3') >= 0) {
                        TotalUnit = parseFloat(unit3);
                        if (TotalUnit > 0) {
                            Ratetemp = (parseFloat(Ratetemp) * parseFloat(TotalUnit));
                        }
                    }
                    if (document.getElementById("hidunit").value.search('u4') >= 0) {
                        TotalUnit = parseFloat(unit4);
                        if (TotalUnit > 0) {
                            Ratetemp = (parseFloat(Ratetemp) * parseFloat(TotalUnit));
                        }
                    }
                    if (document.getElementById("hidunit").value == '') {
                        Ratetemp = parseFloat(TotalUnit) * parseFloat(rate);
                    }
                    GrossAmt = parseFloat(Ratetemp);
                    document.getElementById("txtgrossamtctrl" + lastno).value = parseFloat(GrossAmt);
                }
                else {
                    GrossAmt = document.getElementById("txtgrossamtctrl" + lastno).value;
                }
                if (GrossAmt != null) {
                    var GrossAmount = 0;
                    var servicechargeAmtount = 0;
                    var TotalAmount = 0;
                    if (document.getElementById("hidTaxableNonTaxable" + lastno).value == 'Taxable') {
                        //GrossAmount = (parseFloat(Grandtotal) / GrossRate);
                        servicechargeAmtount = (parseFloat(GrossAmt) * parseFloat(ServiceChargeper) / 100).toFixed(2);
                        TotalAmount = (parseFloat(GrossAmt) + parseFloat(servicechargeAmtount));
                    }
                    else {
                        //GrossAmount = (parseFloat(GrossAmt) / servicechargerate);
                        servicechargeAmtount = (parseFloat(GrossAmt) * parseFloat(ServiceChargeper) / 100).toFixed(2);
                        TotalAmount = (parseFloat(GrossAmt) + parseFloat(servicechargeAmtount));
                    }
                    document.getElementById("txtservicecharge2crtl" + lastno).value = parseFloat(servicechargeAmtount).toFixed(2);      // Service Charge Amount
                    document.getElementById("txtservicecharge3crtl" + lastno).value = parseFloat(TotalAmount).toFixed(2);   // Total Amount Header
                    // Discount 
                    if (document.getElementById("txtdiscount1ctrl" + lastno).value == '') {
                        document.getElementById("txtdiscount1ctrl" + lastno).value = 0;
                    }
                    document.getElementById("txtdiscount2ctrl" + lastno).value = (parseFloat(document.getElementById("txtgrossamtctrl" + lastno).value) * (parseFloat(document.getElementById("txtdiscount1ctrl" + lastno).value)) / 100).toFixed(2);

                    var disserper = ((parseFloat(servicechargeAmtount)) * (parseFloat(document.getElementById("txtdiscount2ctrl" + lastno).value)) / 100).toFixed(2);      // Service Charge Amount
                    document.getElementById("txtservicecharge2crtl" + lastno).value = (parseFloat(servicechargeAmtount) - parseFloat(disserper));
                    var distotper = ((parseFloat(TotalAmount)) * (parseFloat(document.getElementById("txtdiscount2ctrl" + lastno).value)) / 100);
                    document.getElementById("txtservicecharge3crtl" + lastno).value = ((parseFloat(TotalAmount)) - (parseFloat(distotper))).toFixed(2);   // Total Amount Header
                    // Discount End
                    // Service Tax
                    var totalamounthead = parseFloat(document.getElementById("txtservicecharge3crtl" + lastno).value);
                    if (totalamounthead == '') {
                        totalamounthead = 0;
                    }
                    if (document.getElementById("hidTaxableNonTaxable" + lastno).value == 'Taxable') {
                        document.getElementById("txtserviceTax1crtl" + lastno).value = Math.round(parseFloat(parseFloat(totalamounthead)) * parseFloat(servicetaxper) / 100).toFixed(2);    // Service Tax
                        document.getElementById("txtserviceTax2crtl" + lastno).value = (parseFloat(parseFloat(totalamounthead)) * parseFloat(pecesstaxper / 10) / 100).toFixed(2);   // P.E Cess
                        document.getElementById("txtserviceTax3crtl" + lastno).value = (parseFloat(parseFloat(totalamounthead)) * parseFloat(hecesstaxper / 10) / 100).toFixed(2);  // H.E Cess
                        document.getElementById("txtserviceTax4crtl" + lastno).value = '0'; // Luxuary Tax
                        document.getElementById("txtserviceTax5crtl" + lastno).value = '0'; // VAT Tax

                        if (document.getElementById("hidSaleLevel").value == 'ItemLevel') {
                            document.getElementById("txtTaxincGrandTotalctrl" + lastno).value = parseFloat(parseFloat(totalamounthead) + (parseFloat(document.getElementById("txtserviceTax1crtl" + lastno).value)) + (parseFloat(document.getElementById("txtserviceTax2crtl" + lastno).value)) + (parseFloat(document.getElementById("txtserviceTax3crtl" + lastno).value)) + (parseFloat(document.getElementById("txtserviceTax4crtl" + lastno).value)) + (parseFloat(document.getElementById("txtserviceTax5crtl" + lastno).value))).toFixed(2);
                        }
                        else {
                            document.getElementById("txtTaxincGrandTotalctrl" + lastno).value = parseFloat(totalamounthead).toFixed(2);
                        }
                    }
                    else {
                        document.getElementById("txtserviceTax1crtl" + lastno).value = '0';
                        document.getElementById("txtserviceTax2crtl" + lastno).value = '0';
                        document.getElementById("txtserviceTax3crtl" + lastno).value = '0';

                        document.getElementById("txtTaxincGrandTotalctrl" + lastno).value = parseFloat(totalamounthead).toFixed(2);
                    }
                    // Service Tax End
                    ////////// Bottom //////////
                    var totTaxableAmount = 0;
                    var totNonTaxableAmount = 0;
                    var totServiceChargeAmount = 0;
                    var totservAmt = 0;
                    var totpecessAmt = 0;
                    var tothecessAmt = 0;
                    var totluxuaryAmt = 0;
                    var totVatAmt = 0;
                    var TotalAmount = 0;
                    var TotalGrand = 0;
                    for (var i = 1; i <= parseFloat(document.getElementById("hcount").value); i++) {
                        //////////// Txable Amount,NonTaxableAmount,TotalAmount //////////
                        var temptotTaxableAmount = Number(document.getElementById("txtgrossamtctrl" + i).value);
                        var temptotNonTaxableAmount = Number(document.getElementById("txtgrossamtctrl" + i).value);
                        var temptotServiceChargeAmount = Number(document.getElementById("txtservicecharge2crtl" + i).value);
                        var tempTotalAmount = Number(document.getElementById("txtservicecharge3crtl" + i).value);

                        if (temptotTaxableAmount == '' || temptotNonTaxableAmount == '') {
                            temptotTaxableAmount = 0;
                            temptotNonTaxableAmount = 0;
                        }
                        if (document.getElementById("hidTaxableNonTaxable" + i).value == 'Taxable') {
                            totTaxableAmount += parseFloat(temptotTaxableAmount);
                        }
                        else {
                            totNonTaxableAmount += parseFloat(temptotNonTaxableAmount);
                        }
                        if (temptotServiceChargeAmount == '') {
                            temptotServiceChargeAmount = 0;
                        }
                        totServiceChargeAmount += parseFloat(temptotServiceChargeAmount);
                        if (tempTotalAmount == '') {
                            tempTotalAmount = 0;
                        }
                        TotalAmount += parseFloat(tempTotalAmount);

                        var tempservAmt = Number(document.getElementById("txtserviceTax1crtl" + i).value);
                        var temppecessAmt = Number(document.getElementById("txtserviceTax2crtl" + i).value);
                        var temphecessAmt = Number(document.getElementById("txtserviceTax3crtl" + i).value);
                        var templuxuaryAmt = Number(document.getElementById("txtserviceTax4crtl" + i).value);
                        var tempVatAmt = Number(document.getElementById("txtserviceTax5crtl" + i).value);

                        if (tempservAmt == '') {
                            tempservAmt = 0;
                        }
                        totservAmt += Math.round(parseFloat(tempservAmt));
                        if (temppecessAmt == '') {
                            temppecessAmt = 0;
                        }
                        totpecessAmt += parseFloat(temppecessAmt);
                        if (temphecessAmt == '') {
                            temphecessAmt = 0;
                        }
                        tothecessAmt += parseFloat(temphecessAmt);
                        if (templuxuaryAmt == '') {
                            templuxuaryAmt = 0;
                        }
                        totluxuaryAmt += parseFloat(templuxuaryAmt);
                        if (tempVatAmt == null) {
                            tempVatAmt = 0;
                        }
                        totVatAmt += parseFloat(tempVatAmt);

                        var tempTotalGrand = Number(document.getElementById("txtTaxincGrandTotalctrl" + i).value);
                        if (tempTotalGrand == null) {
                            tempTotalGrand = 0;
                        }
                        TotalGrand += parseFloat(tempTotalGrand);

                    }
                    document.getElementById("txttaxableamount").value = parseFloat(totTaxableAmount).toFixed(2);
                    document.getElementById("txtnontaxableamount").value = parseFloat(totNonTaxableAmount).toFixed(2);
                    document.getElementById("txtservicechargeamt").value = parseFloat(totServiceChargeAmount).toFixed(2);
                    document.getElementById("txttotalamount").value = parseFloat(TotalAmount).toFixed(2);

                    document.getElementById("txtservicetax").value = Math.round(parseFloat(totservAmt)).toFixed(2);
                    document.getElementById("txtpecess").value = parseFloat(totpecessAmt).toFixed(2);
                    document.getElementById("txthecess").value = parseFloat(tothecessAmt).toFixed(2);
                    //document.getElementById("txtluxuarytax").value = 0;
                    document.getElementById("txtluxuarytax").value = parseFloat(totluxuaryAmt).toFixed(2);
                    //document.getElementById("txtluxuarytax").value = parseFloat(totVatAmt).toFixed(2);

                    var roundoffamt = 0;
                    var temproundoffamt = 0;

                    temproundoffamt = (parseFloat(TotalAmount) + parseFloat(totservAmt) + parseFloat(totpecessAmt) + parseFloat(tothecessAmt) + parseFloat(totluxuaryAmt)).toFixed(2);
                    roundoffamt = (parseFloat(TotalGrand) - parseFloat(temproundoffamt)).toFixed(2);
                    if (parseFloat(TotalAmount) > parseFloat(TotalGrand)) {
                        roundoffamt = 0 - (parseFloat(TotalGrand) - parseFloat(TotalAmount)).toFixed(2);
                    }
                    else {
                        roundoffamt = 0.00;
                    }

                    document.getElementById("txtroundofamt").value = parseFloat(roundoffamt).toFixed(2);
                    document.getElementById("txtgrandtotal").value = parseFloat(temproundoffamt).toFixed(2);
                }
            }
        }
        function discountbill(taxablenontaxable, id) {
            var lastno = GetLastNumber(id);
            var disper = Number(document.getElementById("txtdiscounttaxper").value);
            var disnonper = Number(document.getElementById("txtnondiscounttaxper").value);
            if (document.getElementById("hidDiscount").value == 'BillLevel') {

                if (taxablenontaxable == 'taxable') {
                    document.getElementById("txtdiscounttaxamt").value = (parseFloat(document.getElementById("txttaxableamount").value) * parseFloat(disper) / 100).toFixed(2);
                }
                else {
                    document.getElementById("txtnondiscounttaxamt").value = (parseFloat(document.getElementById("txtnontaxableamount").value) * parseFloat(disnonper) / 100).toFixed(2);
                }

                var originaltaxableamt = 0;
                var originalnontaxableamt = 0;
                for (var i = 1; i <= parseFloat(document.getElementById("hcount").value); i++) {
                    if (document.getElementById("hidTaxableNonTaxable" + i).value == 'Taxable') {
                        if (document.getElementById("ddlservice" + i).value != '0') {
                            document.getElementById("txtdiscount1ctrl" + i).value = parseFloat(disper);
                            document.getElementById("txtdiscount1ctrl" + i).Blur = "return CalculateGrandTotal('txtdiscount1ctrl' + " + i + ");";
                            //document.getElementById("txtdiscount1ctrl" + i).focus();
                            document.getElementById("txtservicecharge1crtl" + i).focus();
                            document.getElementById("txtgrossamtctrl" + i).focus();
                            document.getElementById("txtTaxincGrandTotalctrl" + i).focus();
                        }
                    }
                    else {
                        if (document.getElementById("ddlservice" + i).value != '0') {
                            document.getElementById("txtdiscount1ctrl" + i).value = parseFloat(disnonper);
                            document.getElementById("txtdiscount1ctrl" + i).Blur = "return CalculateGrandTotal('txtdiscount1ctrl' + " + i + ");";
                            //document.getElementById("txtdiscount1ctrl" + i).focus();
                            document.getElementById("txtservicecharge1crtl" + i).focus();
                            document.getElementById("txtgrossamtctrl" + i).focus();
                            document.getElementById("txtTaxincGrandTotalctrl" + i).focus();
                        }
                    }
                }
            }
        }
        function validatemptyfield() {

            if (document.getElementById("ddlCustomer").value == '0') {
                alert('Select Customer First!');
                document.getElementById("ddlCustomer").focus();
                return false;
            }
            else if (document.getElementById("txtrefno").value == '') {
                alert('Enter Ref No.');
                document.getElementById("txtrefno").focus();
                return false;
            }
            else if (document.getElementById("txtdate").value == '') {
                alert('Enter Date');
                document.getElementById("txtdate").focus();
                return false;
            }
            var count = document.getElementById('hcount').value;
            for (var i = 1; i <= count; i++) {
                if (document.getElementById("ddlservice" + i).value == "0") {
                    alert("Please select Service !");
                    document.getElementById("ddlservice" + i).focus();
                    return false;
                }
                else if (document.getElementById("txtunitrate1ctrl" + i).value == "") {
                    alert("Please specify Unit !");
                    document.getElementById("txtunitrate1ctrl" + i).focus();
                    return false;
                }
                else if (document.getElementById("txtunitrate2ctrl" + i).value == "") {
                    alert("Please specify Rate !");
                    document.getElementById("txtunitrate2ctrl" + i).focus();
                    return false;
                }
            }
            return true;
        }
        function RoundAmountBottom(id) {
            var lastno = GetLastNumber(id);

            var TotalAmount = 0;
            var tempTotalAmount = 0;
            var TotalEntryAmount = 0;
            var tempTotalEntryAmount = 0;
            var TotalTxableamount = 0;
            var TotalTxableamountHeader = 0;
            for (var i = 1; i <= parseFloat(document.getElementById("hcount").value); i++) {
                tempTotalAmount = document.getElementById("txtservicecharge3crtl" + i).value;
                if (tempTotalAmount == '') {
                    tempTotalAmount = 0;
                }
                TotalAmount += parseFloat(tempTotalAmount);
                if (document.getElementById("hidGrandTotal").value == 'yes') {
                    tempTotalEntryAmount = document.getElementById("txtTaxincGrandTotalctrl" + i).value;
                }
                else {
                    tempTotalEntryAmount = document.getElementById("txtservicecharge3crtl" + i).value;
                }
                if (tempTotalEntryAmount == '') {
                    tempTotalEntryAmount = 0;
                }
                TotalEntryAmount += parseFloat(tempTotalEntryAmount);

                if (document.getElementById("hidTaxableNonTaxable" + i).value == 'Taxable') {
                    var servicetaxper = parseFloat(document.getElementById("txtservicetaxpercent").value).toFixed(2);
                    if (servicetaxper == '') {
                        servicetaxper = 0;
                    }
                    var pecesstaxper = parseFloat(document.getElementById("txtpecesspercent").value).toFixed(2);
                    if (pecesstaxper == '') {
                        pecesstaxper = 0;
                    }
                    var hecesstaxper = parseFloat(document.getElementById("txthecesspercent").value).toFixed(2);
                    if (hecesstaxper == '') {
                        hecesstaxper = 0;
                    }
                    var luxuarytaxper = parseFloat(document.getElementById("txtluxuarytaxpercent").value).toFixed(2);
                    if (luxuarytaxper == '') {
                        luxuarytaxper = 0;
                    }
                    var temptotaltaxableamount = document.getElementById("txtservicecharge3crtl" + i).value;
                    if (temptotaltaxableamount == '') {
                        temptotaltaxableamount = 0;
                    }
                    TotalTxableamount += parseFloat(temptotaltaxableamount);
                    document.getElementById("txtservicetax").value = (parseFloat(parseFloat(TotalTxableamount)) * parseFloat(servicetaxper) / 100).toFixed(2);
                    document.getElementById("txtpecess").value = (parseFloat(parseFloat(TotalTxableamount)) * parseFloat(pecesstaxper / 10) / 100).toFixed(2);
                    document.getElementById("txthecess").value = (parseFloat(parseFloat(TotalTxableamount)) * parseFloat(hecesstaxper / 10) / 100).toFixed(2);
                    document.getElementById("txtluxuarytax").value = '0';
                }

            }


            if (document.getElementById("hidSaleLevel").value == "ItemLevel") {
                var temptotaltaxableamountheader = document.getElementById("txtservicecharge3crtl" + lastno).value;
                if (temptotaltaxableamountheader == '') {
                    temptotaltaxableamountheader = 0;
                }
                TotalTxableamountHeader = parseFloat(temptotaltaxableamountheader);
                document.getElementById("txtserviceTax1crtl" + lastno).value = (parseFloat(parseFloat(TotalTxableamountHeader)) * parseFloat(servicetaxper) / 100).toFixed(2);    // Service Tax
                document.getElementById("txtserviceTax2crtl" + lastno).value = (parseFloat(parseFloat(TotalTxableamountHeader)) * parseFloat(pecesstaxper / 10) / 100).toFixed(2);   // P.E Cess
                document.getElementById("txtserviceTax3crtl" + lastno).value = (parseFloat(parseFloat(TotalTxableamountHeader)) * parseFloat(hecesstaxper / 10) / 100).toFixed(2);  // H.E Cess
            }

            var servicetaxamount = document.getElementById("txtservicetax").value;
            if (servicetaxamount == '') {
                servicetaxamount = 0;
            }
            var TaxPeCessamount = document.getElementById("txtpecess").value;
            if (TaxPeCessamount == '') {
                TaxPeCessamount = 0;
            }
            var TaxHeCessamount = document.getElementById("txthecess").value;
            if (TaxHeCessamount == '') {
                TaxHeCessamount = 0;
            }
            var TaxLuxuaryTax = document.getElementById("txtluxuarytax").value;
            if (TaxLuxuaryTax == '') {
                TaxLuxuaryTax = 0;
            }

            var roundoffamt = 0;
            var temproundoffamt = 0;

            temproundoffamt = (parseFloat(TotalAmount) + parseFloat(servicetaxamount) + parseFloat(TaxPeCessamount) + parseFloat(TaxHeCessamount) + parseFloat(TaxLuxuaryTax)).toFixed(2);
            roundoffamt = (parseFloat(TotalEntryAmount) - parseFloat(temproundoffamt)).toFixed(2);
            if (parseFloat(TotalAmount) > parseFloat(TotalEntryAmount)) {
                roundoffamt = 0 - (parseFloat(TotalAmount) - parseFloat(TotalEntryAmount)).toFixed(2);
            }
            //alert(TotalAmount);
            document.getElementById("txtroundofamt").value = roundoffamt;
            document.getElementById("txtgrandtotal").value = TotalEntryAmount.toFixed(2);
        }
        function PostBilling(id) {
            if (id == 'chkapplysurcurr') {
                if (document.getElementById(id).checked) {
                    document.getElementById("txteffectiveratecurr").value = parseFloat(document.getElementById("hideffectiverate").value);
                }
                else {
                    document.getElementById("txteffectiveratecurr").value = (parseFloat(document.getElementById("hideffectiverate").value) - parseFloat(document.getElementById("hidsurchargerate").value));
                }
            }
            else {
                if (document.getElementById(id).checked) {
                    document.getElementById("txteffectiveratepre").value = parseFloat(document.getElementById("hideffectiverate").value);
                }
                else {
                    document.getElementById("txteffectiveratepre").value = (parseFloat(document.getElementById("hideffectiverate").value) - parseFloat(document.getElementById("hidsurchargerate").value));
                }
            }

        }
        function checkAlLChecked() {
            var Count = document.getElementById("hCount").value;
            var j = 0;
            for (var i = 1; i <= Count; i++) {
                var checkbx = document.getElementById("chkDelete" + i.toString());
                if (checkbx.checked == true) {
                    j++;
                }
                if (j == Count) {
                    alert("All record can't be deleted !");
                    checkbx.checked = false;
                    break;
                }
            }
        }
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <div class="divmain" style="width: 96%; margin-left: 1%;">
        <acc:heading ID="pagehead" runat="server" HeadingText="Edit Sale Invoice" />
        <div style="margin-left: 5%; margin-right: 3%; width: 85%" align="center">
            <asp:Label ID="lblMsg" runat="server" Font-Bold="true"></asp:Label>
        </div>
    </div>
    <div style="width: 96%; margin-left: 1%; margin-top: 10px;">
        <table style="width: 100%;" class="tablecontent">
            <tr>
                <td>
                    <b>Bill Format <span style="color: Red">* </span></b>
                </td>
                <td>
                    <asp:DropDownList ID="ddlFormat" runat="server" CssClass="dropdown">
                    </asp:DropDownList>
                    <asp:HiddenField ID="hidTranType" runat="server" />
                    <asp:HiddenField ID="hidSaleLevel" runat="server" />
                    <%-- Item Level Or Bill Level --%>
                    <asp:HiddenField ID="hidGrandTotal" runat="server" />
                    <%-- TaxInclusive             --%>
                    <asp:HiddenField ID="hidsercharge" runat="server" />
                    <%-- Show Service Charge      --%>
                    <asp:HiddenField ID="hidTaxType" runat="server" />
                    <%-- ServiceTax ServiceTax,LuxuaryTax ServiceTax,VAT --%>
                    <asp:HiddenField ID="hidDiscount" runat="server" />
                    <%-- Apply Discount None,BillLevel,ItemLevel --%>
                    <asp:HiddenField ID="hidunit" runat="server" />
                    <%-- Addition Unit Height,Widht,Radious --%>
                    <asp:HiddenField ID="hidunitrate" runat="server" />
                    <%-- Unit and Rate            --%>
                </td>
                <td>
                    <b>Customer <span style="color: Red;">* </span></b>
                </td>
                <td>
                    <asp:DropDownList ID="ddlCustomer" runat="server" CssClass="dropdown" AutoPostBack="true"
                        onchange="clearfields();" OnSelectedIndexChanged="ddlCustomer_SelectedIndex"
                        Width="200px">
                    </asp:DropDownList>
                </td>
            </tr>
            <tr>
                <td>
                    <b>Bill No. <span style="color: Red;">* </span></b>
                </td>
                <td>
                    <asp:TextBox ID="txtPrefix" runat="server" Width="60px" CssClass="input" onKeyPress="return false"
                        onKeydown="EnabledTabKey(this.id, event);"></asp:TextBox>
                    <ajaxcontrol:textboxwatermarkextender id="prefixWater" runat="server" targetcontrolid="txtPrefix"
                        watermarktext="Prefix" watermarkcssclass="watermark_textbox"></ajaxcontrol:textboxwatermarkextender>
                    <asp:TextBox ID="txtbillno" runat="server" Width="60px" CssClass="inputnumber" ValidationGroup="V"
                        MaxLength="10"></asp:TextBox>
                    <ajaxcontrol:textboxwatermarkextender id="voucherWater" runat="server" targetcontrolid="txtbillno"
                        watermarktext="Number" watermarkcssclass="watermark_textbox"></ajaxcontrol:textboxwatermarkextender>
                    <asp:TextBox ID="txtSuffix" runat="server" Width="60px" CssClass="input" onKeyPress="return false"
                        onKeydown="EnabledTabKey(this.id, event);"></asp:TextBox>
                    <ajaxcontrol:textboxwatermarkextender id="suffixWater" runat="server" targetcontrolid="txtSuffix"
                        watermarktext="Suffix" watermarkcssclass="watermark_textbox"></ajaxcontrol:textboxwatermarkextender>
                </td>
                <td>
                    <b>Address</b>
                </td>
                <td colspan="5">
                    <asp:TextBox ID="txtaddress" runat="server" CssClass="input" Width="200px"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    <b>Date <span style="color: Red;">* </span></b>
                </td>
                <td>
                    <asp:TextBox ID="txtdate" runat="server" CssClass="input" AutoPostBack="true"></asp:TextBox>
                    <asp:ImageButton ID="btnDate" runat="server" ImageUrl="~/Images/calendar.gif" />
                    <ajaxcontrol:calendarextender id="calrec" runat="server" popupbuttonid="btnDate"
                        targetcontrolid="txtdate" format="dd/MM/yyyy"></ajaxcontrol:calendarextender>
                    <ajaxcontrol:maskededitextender id="maskExtrec" runat="server" masktype="Date" mask="99/99/9999"
                        targetcontrolid="txtdate" culturename="en-GB"></ajaxcontrol:maskededitextender>
                    <ajaxcontrol:maskededitvalidator id="maskValidrec" runat="server" controlextender="maskExtrec"
                        invalidvaluemessage="Invalid Date" isvalidempty="true" display="Dynamic" validationgroup="V"
                        controltovalidate="txtdate"></ajaxcontrol:maskededitvalidator>
                </td>
                <td>
                    <b>Ref no <span style="color: Red">*</span></b>
                </td>
                <td>
                    <asp:TextBox ID="txtrefno" runat="server" CssClass="inputnumber" MaxLength="50" Style="width: 70px;"></asp:TextBox>
                </td>
            </tr>
            <tr>
                <td>
                    <b>Other Ref</b>
                </td>
                <td>
                    <asp:TextBox ID="txtotherref" MaxLength="48" runat="server" CssClass="input" Style="width: 70px;"></asp:TextBox>
                </td>
                <td>
                    <b>Cr Days</b>
                </td>
                <td>
                    <asp:TextBox ID="txtcrdays" runat="server" CssClass="input" MaxLength="3" Style="width: 70px;
                        text-align: right;" OnKeyPress="return isNumberKey(this.id,event);"></asp:TextBox>
                    <asp:HiddenField ID="hidCustomerprefid" runat="server" />
                </td>
            </tr>
        </table>
        <div style="width: 100%; margin-top: 10px;">
            <asp:Panel ID="pnlmain" runat="server" Wrap="false" ScrollBars="Both" Width="100%">
                <asp:HiddenField ID="hcount" runat="server" Value="1" />
                <table id="tblmain" runat="server" class="tablecontent" width="100%" style="margin-bottom: 10px;">
                    <tr>
                        <td style="border-right: 1px solid #818181;" class="headtd">
                            <center>
                               <span style=""><asp:Literal ID="lt1" runat="server" Text="Delete"></asp:Literal></span></center>
                        </td>
                        <td style="border-right: 1px solid #818181; " class="headtd" align="center" id="tdservice"
                            runat="server">
                            <b><span style=""><asp:Literal ID="Literal1" runat="server" Text="Nature of Service"></asp:Literal></span></b>
                        </td>
                        <td style="border-right: 1px solid #818181; display:none;" class="headtd" align="center" id="tddescription" runat="server">
                            <b><span style=""><asp:Literal ID="Literal2" runat="server" Text="Description"></asp:Literal></span></b>
                        </td>
                        <td style="display: none;  border-right: 1px solid #818181;" class="headtd" align="center"
                            id="tdyearref" runat="server">
                            <b><span style=""><asp:Literal ID="Literal3"  runat="server" Text="Year Ref."></asp:Literal></span></b>
                        </td>
                        <td style="display: none;  border-right: 1px solid #818181;" class="headtd" align="center"
                            id="tduom" runat="server">
                            <b><span style=""><asp:Literal ID="Literal4" runat="server" Text="UOM"></asp:Literal></span></b>
                        </td>
                        <td style="display: none;  border-right: 1px solid #818181;" class="headtd" align="center"
                            id="tdunit2" runat="server">
                            <b><span style=""><asp:Literal ID="Literal5" runat="server" Text="Unit 2"></asp:Literal></span></b>
                        </td>
                        <td style="display: none;  border-right: 1px solid #818181;" class="headtd" align="center"
                            id="tdunit3" runat="server">
                            <b><span style=""><asp:Literal ID="Literal6" runat="server" Text="Unit 3"></asp:Literal></span></b>
                        </td>
                        <td style="display: none; border-right: 1px solid #818181;" class="headtd" align="center"
                            id="tdunit4" runat="server">
                            <b><span style=""><asp:Literal ID="Literal7" runat="server" Text="Unit 4"></asp:Literal></span></b>
                        </td> 
                        <td style="display: none; border-right: 1px solid #818181;" class="headtd" align="center"
                            id="tdunitrate1" runat="server">
                            <b><span style=""><asp:Literal ID="Literal8" runat="server" Text="Unit"></asp:Literal></span></b>
                        </td>
                        <td style="border-right: 1px solid #818181; " class="headtd" align="center" id="tdunitrate2"
                            runat="server">
                            <b><span style=""><asp:Literal ID="Literal9" runat="server" Text="Rate"></asp:Literal></span></b>
                        </td>
                        <td style="border-right: 1px solid #818181; " class="headtd" align="center" id="tdgrossamt"
                            runat="server">
                            <b><span style=""><asp:Literal ID="Literal10" runat="server" Text="Gross Amount"></asp:Literal></span></b>
                        </td>
                        <td style="display: none; border-right: 1px solid #818181; " class="headtd" align="center"
                            id="tddiscount1" runat="server">
                            <b><span style=""><asp:Literal ID="Literal11" runat="server" Text="Discount %"></asp:Literal></span></b>
                        </td>
                        <td style="display: none; border-right: 1px solid #818181; " class="headtd" align="center"
                            id="tddiscount2" runat="server">
                            <b><span style=""><asp:Literal ID="Literal12" runat="server" Text="Discount Amount"></asp:Literal></span></b>
                        </td>
                        <td style="display: none; border-right: 1px solid #818181;" class="headtd" align="center"
                            id="tdservicecharge1" runat="server">
                            <b><span style=""><asp:Literal ID="Literal13" runat="server" Text="Service Charge %"></asp:Literal></span></b>
                        </td>
                        <td style="display: none; border-right: 1px solid #818181;" class="headtd" align="center"
                            id="tdservicecharge2" runat="server">
                            <b><span style=""><asp:Literal ID="Literal14" runat="server" Text="Service Charge"></asp:Literal></span></b>
                        </td>
                        <td style="display: none; border-right: 1px solid #818181;" class="headtd" align="center"
                            id="tdservicecharge3" runat="server">
                            <b><span style=""><asp:Literal ID="Literal15" runat="server" Text="Total Amount"></asp:Literal></span></b>
                        </td>
                        <td style="display: none; border-right: 1px solid #818181;" class="headtd" align="center"
                            id="tdserviceTax1" runat="server">
                            <b><span style=""><asp:Literal ID="Literal16" runat="server" Text="Service Tax"></asp:Literal></span></b>
                        </td>
                        <td style="display: none; border-right: 1px solid #818181;" class="headtd" align="center"
                            id="tdserviceTax2" runat="server">
                            <b><span style=""><asp:Literal ID="Literal17" runat="server" Text="P.E.Cess"></asp:Literal></span></b>
                        </td>
                        <td style="display: none; border-right: 1px solid #818181;" class="headtd" align="center"
                            id="tdserviceTax3" runat="server">
                            <b><span style=""><asp:Literal ID="Literal18" runat="server" Text="H.E.Cess"></asp:Literal></span></b>
                        </td>
                        <td style="display: none; border-right: 1px solid #818181;" class="headtd" align="center"
                            id="tdserviceTax4" runat="server">
                            <b><span style=""><asp:Literal ID="Literal19" runat="server" Text="Luxury"></asp:Literal></span></b>
                        </td>
                        <td style="display: none; border-right: 1px solid #818181;" class="headtd" align="center"
                            id="tdserviceTax5" runat="server">
                            <b><span style=""><asp:Literal ID="Literal20" runat="server" Text="VAT"></asp:Literal></span></b>
                        </td>
                        <td style="display: none;"  class="headtd" align="center" id="tdTaxincGrandTotal"
                            runat="server">
                            <b><span style=""><asp:Literal ID="Literal21" runat="server" Text="Grand Total"></asp:Literal></span></b>
                        </td>
                    </tr>
                    <tr>
                        <td style="width: 20px; vertical-align: top; text-align:center;" align="center">
                            <center><asp:CheckBox ID="chkDelete1" runat="server" Width="20px" onclick="checkAlLChecked();CalculateGrandTotal(this.id);" /></center>
                            <asp:HiddenField ID="hidChildID1" runat="server" Value="0" />
                        </td>
                        <td id="tdservicectrl1" style="width:150px;" runat="server" align="center">
                            <asp:DropDownList ID="ddlservice1" runat="server" AutoPostBack="true" CssClass="dropdown"
                                Width="150px" OnSelectedIndexChanged="ddlservice_SelectedIndexChanged" onchange="return ValidateRequired(this.id);">
                            </asp:DropDownList>
                            <asp:HiddenField ID="hidTaxableNonTaxable1" runat="server" />
                            <asp:HiddenField ID="hidserviceLid1" runat="server" />
                        </td>
                        <td style="display: none; width:120px;" id="tddescriptionctrl1" runat="server" align="center">
                            <asp:TextBox ID="txtdescriptionctrl1" Width="120px" runat="server" CssClass="input" MaxLength="248"
                                Style="display: none;"></asp:TextBox>
                        </td>
                        <td style="display: none; width:70px;" id="tdyearrefctrl1" runat="server" align="center">
                            <asp:TextBox ID="txtyearrefctrl1" runat="server" CssClass="input" Width="70px"
                               Style="display: none;" MaxLength="48"></asp:TextBox>
                        </td>
                        <td style="display: none; width:70px;" id="tduomctrl1" runat="server" align="center">
                            <asp:TextBox ID="txtuomctrl1" runat="server" CssClass="input" MaxLength="25" Width="70px" Style="display: none;"></asp:TextBox>
                        </td>
                        <td style="display: none; width:70px;" id="tdunit2ctrl1" runat="server" align="center">
                            <asp:TextBox ID="txtunit2ctrl1" runat="server" CssClass="inputnumber" MaxLength="10"
                              Width="70px" Style="display: none;" OnKeyPress="return isNumberKey(this.id,event);"></asp:TextBox>
                        </td>
                        <td style="display: none; width:70px;" id="tdunit3ctrl1" runat="server" align="center">
                            <asp:TextBox ID="txtunit3ctrl1" runat="server" CssClass="inputnumber" MaxLength="10"
                               Width="70px" Style="display: none;" OnKeyPress="return isNumberKey(this.id,event);"></asp:TextBox>
                        </td>
                        <td style="display: none; width:70px;" id="tdunit4ctrl1" runat="server" align="center">
                            <asp:TextBox ID="txtunit4ctrl1" runat="server" CssClass="inputnumber" MaxLength="10"
                                Width="70px" Style="display: none;" OnKeyPress="return isNumberKey(this.id,event);"></asp:TextBox>
                        </td>
                        <td style="display: none; width:70px;" id="tdunitrate1ctrl1" runat="server" align="center">
                            <asp:TextBox ID="txtunitrate1ctrl1" runat="server" CssClass="inputnumber" MaxLength="10"
                               Width="70px" Style="display: none;" OnKeyPress="return isNumberKey(this.id,event);"
                                onBlur="return CalculateGrandTotal(this.id);"></asp:TextBox>
                        </td>
                        <td id="tdunitrate2ctrl1" style="width:70px;" runat="server" align="center">
                            <asp:TextBox ID="txtunitrate2ctrl1" runat="server" CssClass="inputnumber" Width="70px"
                                MaxLength="10" onBlur="return CalculateGrandTotal(this.id);" OnKeyPress="return isNumberKey(this.id,event);"></asp:TextBox>
                        </td>
                        <td id="tdgrossamtctrl1" style="width:120px;" runat="server" align="center">
                            <asp:TextBox ID="txtgrossamtctrl1" runat="server" CssClass="inputnumber" Width="120px"
                                OnKeyPress="return isNumberKey(this.id,event);"></asp:TextBox><asp:HiddenField ID="hidServiceCharge1"
                                    runat="server" />
                        </td>
                        <td style="display: none; width:80px;" id="tddiscount1ctrl1" runat="server" align="center">
                            <asp:TextBox ID="txtdiscount1ctrl1" runat="server" Width="80px" Style="display: none;"
                                CssClass="inputnumber" OnKeyPress="return isNumberKey(this.id,event);" onBlur="return CalculateGrandTotal(this.id);"></asp:TextBox>
                        </td>
                        <td style="display: none; width:120px;" id="tddiscount2ctrl1" runat="server" align="center">
                            <asp:TextBox ID="txtdiscount2ctrl1" runat="server" Width="120px" Style="display: none;"
                                CssClass="DisableInputNumber" onKeyDown="return EnabledTabKey(this.id, event);"></asp:TextBox>
                        </td>
                        <td style="display: none; width:120px;" id="tdservicecharge1crtl1" runat="server" align="center">
                            <asp:TextBox ID="txtservicecharge1crtl1" MaxLength="5" Width="120px" Style="display: none;"
                                runat="server" CssClass="inputnumber" OnKeyPress="return isNumberKey(this.id,event);"
                                onBlur="return CalculateGrandTotal(this.id);"></asp:TextBox>
                        </td>
                        <td style="display: none;width:100px;" id="tdservicecharge2crtl1" runat="server" align="center">
                            <asp:TextBox ID="txtservicecharge2crtl1" MaxLength="5" Width="100px" Style="display: none;"
                                runat="server" CssClass="DisableInputNumber" onKeyDown="return EnabledTabKey(this.id, event);"></asp:TextBox>
                        </td>
                        <td style="display: none; width:100px;" id="tdservicecharge3crtl1" runat="server" align="center">
                            <asp:TextBox ID="txtservicecharge3crtl1" MaxLength="5" Width="100px" Style="display: none;"
                                runat="server" CssClass="DisableInputNumber" onKeyDown="return EnabledTabKey(this.id, event);"></asp:TextBox>
                        </td>
                        <td style="display: none; width:100px;" id="tdserviceTax1crtl1" runat="server" align="center">
                            <asp:TextBox ID="txtserviceTax1crtl1" Width="100px" Style="display: none;" runat="server"
                                CssClass="DisableInputNumber" onKeyDown="return EnabledTabKey(this.id, event);"></asp:TextBox>
                        </td>
                        <td style="display: none; width:70px;" id="tdserviceTax2crtl1" runat="server" align="center">
                            <asp:TextBox ID="txtserviceTax2crtl1" Width="70px" Style="display: none;" runat="server"
                                CssClass="DisableInputNumber" onKeyDown="return EnabledTabKey(this.id, event);"></asp:TextBox>
                        </td>
                        <td style="display: none; width:70px;" id="tdserviceTax3crtl1" runat="server" align="center">
                            <asp:TextBox ID="txtserviceTax3crtl1" Width="70px" Style="display: none;" runat="server"
                                CssClass="DisableInputNumber" onKeyDown="return EnabledTabKey(this.id, event);"></asp:TextBox>
                        </td>
                        <td style="display: none; width:70px;" id="tdserviceTax4crtl1" runat="server" align="center">
                            <asp:TextBox ID="txtserviceTax4crtl1" Width="70px" Style="display: none;" runat="server"
                                CssClass="DisableInputNumber" onKeyDown="return EnabledTabKey(this.id, event);"></asp:TextBox>
                        </td>
                        <td style="display: none; width:70px;" id="tdserviceTax5crtl1" runat="server" align="center">
                            <asp:TextBox ID="txtserviceTax5crtl1" Width="70px" Style="display: none;" runat="server"
                                CssClass="DisableInputNumber" onKeyDown="return EnabledTabKey(this.id, event);"></asp:TextBox>
                        </td>
                        <td style="display: none; width:120px;" id="tdTaxincGrandTotalctrl1" runat="server" align="center">
                            <asp:TextBox ID="txtTaxincGrandTotalctrl1" runat="server" Width="120px" Style="display: none;"
                                CssClass="DisableInputNumber" OnKeyPress="return isNumberKey(this.id,event);"
                                onBlur="return CalculateGrandTotal(this.id);"></asp:TextBox>
                        </td>
                    </tr>
                </table>
            </asp:Panel>
            <table style="width: 90%; margin-top: 10px; margin-bottom: 10px; margin-left: 15px;"
                align="left">
                <tr>
                    <td>
                        <asp:LinkButton ID="btnAddMore" runat="server" OnClick="AddMore_Click"> 
                                        <img src="../../Images/More.jpg" alt="Add New Row" />
                        </asp:LinkButton>
                    </td>
                </tr>
            </table>
        </div>
    </div>
    <table style="width: 96%; margin-left: 1%; margin-top: 10px;" class="tablecontent">
        <tr>
            <td style="width: 60%;" valign="top">
                <table style="width: 100%; margin-top: 4px;" class="tablecontent">
                    <tr>
                        <td>
                            <table style="width: 100%;" cellpadding="0" cellspacing="0">
                                <tr>
                                    <td class="headtd" style="width: 100%;" colspan="3">
                                        <b>Post Billing</b>
                                        <asp:HiddenField ID="hidamtcess" runat="server" />
                                        <asp:HiddenField ID="hidtdsrate" runat="server" />
                                        <asp:HiddenField ID="hidcess1rate" runat="server" />
                                        <asp:HiddenField ID="hidcess2rate" runat="server" />
                                        <asp:HiddenField ID="hidsurchargerate" runat="server" />
                                        <asp:HiddenField ID="hideffectiverate" runat="server" />
                                    </td>
                                </tr>
                                <tr>
                                    <td class="headtd" style="width: 100%;" colspan="3">
                                        <b>Current Bill</b>
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="3">
                                        <asp:CheckBox ID="chkapplysurcurr" runat="server" Text="ApplySurcharge" Checked="true"
                                            onclick="return PostBilling(this.id);" />
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <b>Effective Rate</b>
                                    </td>
                                    <td>
                                        <b>Net TDS</b>
                                    </td>
                                    <td>
                                        <b>Net Amt Receivable </b>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <asp:TextBox ID="txteffectiveratecurr" runat="server" CssClass="DisableInputNumber"
                                            Enabled="false" Style="width: 120px;"></asp:TextBox>
                                    </td>
                                    <td>
                                        <asp:TextBox ID="txtnettdscurr" runat="server" CssClass="DisableInputNumber" Enabled="false"
                                            Style="width: 120px;"></asp:TextBox>
                                    </td>
                                    <td>
                                        <asp:TextBox ID="txtnetamtreceiablecurr" runat="server" CssClass="DisableInputNumber"
                                            Enabled="false" Style="width: 120px;"></asp:TextBox>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="headtd" style="width: 100%;" colspan="3">
                                        <b>Previous Bill</b>
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="3">
                                        <asp:CheckBox ID="chkappsurpre" runat="server" Text="ApplySurcharge" Checked="true"
                                            onclick="return PostBilling(this.id);" />
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <b>Effective Rate</b>
                                    </td>
                                    <td>
                                        <b>Net TDS</b>
                                    </td>
                                    <td colspan="2">
                                        <b>Net Amt Receivable </b>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        <asp:TextBox ID="txteffectiveratepre" runat="server" CssClass="DisableInputNumber"
                                            Enabled="false" Style="width: 120px;"></asp:TextBox>
                                    </td>
                                    <td>
                                        <asp:TextBox ID="txtnettdspre" runat="server" CssClass="DisableInputNumber" Enabled="false"
                                            Style="width: 120px;"></asp:TextBox>
                                    </td>
                                    <td colspan="2">
                                        <asp:TextBox ID="txtnetamtreceiablepre" runat="server" CssClass="DisableInputNumber"
                                            Enabled="false" Style="width: 120px;"></asp:TextBox>
                                    </td>
                                </tr>
                            </table>
                            <table style="width: 100%; margin-top: 10px;">
                                <tr>
                                    <td id="tdnarration" runat="server">
                                        <b>Narration</b>
                                    </td>
                                    <td id="tdnarrationtext" runat="server">
                                        <asp:TextBox ID="txtnarration" runat="server" CssClass="input" MaxLength="150" Style="width: 130px;"></asp:TextBox>
                                    </td>
                                    <td id="tdservicedby" runat="server">
                                        <b>Serviced By</b>
                                    </td>
                                    <td id="tdservicedbytext" runat="server">
                                        <asp:TextBox ID="txtservicedby" runat="server" CssClass="input" MaxLength="50" Style="width: 130px;"></asp:TextBox>
                                    </td>
                                </tr>
                                <tr>
                                    <td id="tdpreparedby" runat="server">
                                        <b>Prepared By</b>
                                    </td>
                                    <td id="tdpreparedbytext">
                                        <asp:TextBox ID="txtpreparedby" runat="server" CssClass="input" MaxLength="50" Style="width: 130px;"></asp:TextBox>
                                    </td>
                                    <td id="tdcheckedby" runat="server">
                                        <b>Checked By</b>
                                    </td>
                                    <td id="tdcheckedbytext">
                                        <asp:TextBox ID="txtcheckedby" runat="server" CssClass="input" MaxLength="50" Style="width: 130px;"></asp:TextBox>
                                    </td>
                                </tr>
                                <tr>
                                    <td id="tdremarks" runat="server">
                                        <b>Remarks</b>
                                    </td>
                                    <td id="tdremarkstext" colspan="3" style="width: 80%;">
                                        <asp:TextBox ID="txtremarks" runat="server" Style="width: 80%;" MaxLength="98" CssClass="input"></asp:TextBox>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </table>
            </td>
            <td style="width: 40%;" valign="top">
                <table id="tblcalculation" runat="server" style="width: 100%; margin-top: 4px;" class="tablecontent">
                    <tr>
                        <td class="headtd" colspan="3">
                            &nbsp;
                        </td>
                    </tr>
                    <tr>
                        <td id="tdtaxableamt" runat="server" colspan="2">
                            <b>Taxable Amount</b>&nbsp;
                        </td>
                        <td id="tdtaxableamttext" runat="server" align="right" style="width: 110px;">
                            &nbsp;<asp:TextBox ID="txttaxableamount" runat="server" CssClass="DisableInputNumber" onKeyDown="return EnabledTabKey(this.id, event);"
                                Style="width: 100px;"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td id="tddiscounttax" runat="server" style="display: none;">
                            <b>Discount</b>&nbsp;
                        </td>
                        <td id="tddiscounttaxper" runat="server" align="right" style="width: 80px; display: none;">
                            &nbsp;<asp:TextBox ID="txtdiscounttaxper" runat="server" Width="70px" onblur="discountbill('taxable',this.id);"
                                CssClass="inputnumber" Style="display: none;" OnKeyPress="return isNumberKey(this.id,event);"></asp:TextBox>
                        </td>
                        <td id="tddiscounttaxamt" runat="server" align="right" style="width: 110px; display: none;">
                            &nbsp;<asp:TextBox ID="txtdiscounttaxamt" runat="server" CssClass="DisableInputNumber"
                                Style="width: 100px; display: none;"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td id="tdnontaxableamt" runat="server" style="display: none;" colspan="2">
                            <b>Non-Taxable Amount</b>&nbsp;
                        </td>
                        <td id="tdnontaxableamttext" runat="server" align="right" style="width: 110px; display: none;">
                            &nbsp;<asp:TextBox ID="txtnontaxableamount" runat="server" CssClass="DisableInputNumber"
                                onKeyDown="return EnabledTabKey(this.id, event);" Style="width: 100px; display: none;"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td id="tddiscountnontax" runat="server" style="display: none;">
                            <b>Discount</b>&nbsp;
                        </td>
                        <td id="tdnondiscountper" runat="server" align="right" style="width: 80px; display: none;">
                            &nbsp;<asp:TextBox ID="txtnondiscounttaxper" runat="server" Width="70px" onblur="discountbill('nontaxable',this.id);"
                                CssClass="inputnumber" Style="display: none;" OnKeyPress="return isNumberKey(this.id,event);"></asp:TextBox>
                        </td>
                        <td id="tdnondiscounttaxamt" runat="server" align="right" style="width: 110px;
                            display: none;">
                           &nbsp;<asp:TextBox ID="txtnondiscounttaxamt" runat="server" CssClass="DisableInputNumber"
                                Style="width: 100px; display: none;"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td id="tdservicechargeamt" runat="server" style="display: none;" colspan="2">
                            <b>Service Charge Amount</b>&nbsp;
                        </td>
                        <td id="tdservicechargeamttext" runat="server" align="right" style="width: 110px;
                            display: none;">
                            &nbsp;<asp:TextBox ID="txtservicechargeamt" runat="server" CssClass="DisableInputNumber"
                                onKeyDown="return EnabledTabKey(this.id, event);" Style="width: 100px; display: none;"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td id="tdtotalamount" runat="server" colspan="2">
                            <b>Total Amount</b>&nbsp;
                        </td>
                        <td id="tdtotalamounttext" runat="server" align="right" style="width: 110px;">
                            &nbsp;<asp:TextBox ID="txttotalamount" runat="server" align="right" CssClass="DisableInputNumber"
                                onKeyDown="return EnabledTabKey(this.id, event);" Style="width: 100px;"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td id="tdservicetax" runat="server">
                            <b>Service Tax %</b>&nbsp;
                        </td>
                        <td id="tdservicetaxtext" runat="server" align="right" style="width: 80px;">
                            &nbsp;<asp:TextBox ID="txtservicetaxpercent" runat="server" Width="70px" CssClass="DisableInputNumber"
                                onKeyDown="return EnabledTabKey(this.id, event);"></asp:TextBox><asp:HiddenField
                                    ID="hidservicetaxpercent" runat="server" />
                        </td>
                        <td align="right" style="width: 110px;">
                           &nbsp;<asp:TextBox ID="txtservicetax" runat="server" CssClass="DisableInputNumber" onKeyDown="return EnabledTabKey(this.id, event);"
                                Style="width: 100px;"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td id="tdpecess" runat="server">
                            <b>P.E Cess %</b>&nbsp;
                        </td>
                        <td id="tdpecesstext" runat="server" align="right" style="width: 80px;">
                           &nbsp;<asp:TextBox ID="txtpecesspercent" runat="server" Width="70px" CssClass="DisableInputNumber"
                                onKeyDown="return EnabledTabKey(this.id, event);"></asp:TextBox><asp:HiddenField
                                    ID="hidpecesspercent" runat="server" />
                        </td>
                        <td align="right" style="width: 110px;">
                            &nbsp;<asp:TextBox ID="txtpecess" runat="server" CssClass="DisableInputNumber" onKeyDown="return EnabledTabKey(this.id, event);"
                                Style="width: 100px;"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td id="tdhecess" runat="server">
                            <b>H.E Cess %</b>&nbsp;
                        </td>
                        <td id="tdhecesstext" runat="server" align="right" style="width: 80px;">
                            &nbsp;<asp:TextBox ID="txthecesspercent" runat="server" Width="70px" CssClass="DisableInputNumber"
                                onKeyDown="return EnabledTabKey(this.id, event);"></asp:TextBox><asp:HiddenField
                                    ID="hidhecesspercent" runat="server" />
                        </td>
                        <td align="right" style="width: 110px;">
                            &nbsp;<asp:TextBox ID="txthecess" runat="server" CssClass="DisableInputNumber" onKeyDown="return EnabledTabKey(this.id, event);"
                                Style="width: 100px;"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td id="tdluxuarytax" runat="server">
                            <b>Luxuary Tax %</b>&nbsp;
                        </td>
                        <td id="tdluxuarytaxtext" runat="server" align="right" style="width: 80px;">
                            &nbsp;<asp:TextBox ID="txtluxuarytaxpercent" runat="server" Width="70px" CssClass="DisableInputNumber"
                                onKeyDown="return EnabledTabKey(this.id, event);"></asp:TextBox><asp:HiddenField
                                    ID="hidluxuarytaxpercent" runat="server" />
                        </td>
                        <td align="right" style="width: 110px;">
                            &nbsp;<asp:TextBox ID="txtluxuarytax" runat="server" CssClass="DisableInputNumber" Style="width: 100px;"
                                onKeyDown="return EnabledTabKey(this.id, event);"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td id="tdroundofamt" runat="server" colspan="2">
                            <b>Round Off Amount</b>&nbsp;
                        </td>
                        <td id="tdroundofamttext" runat="server"  align="right">
                            &nbsp;<asp:TextBox ID="txtroundofamt" runat="server" CssClass="DisableInputNumber" onKeyDown="return EnabledTabKey(this.id, event);"
                                Style="width: 100px;"></asp:TextBox>
                        </td>
                    </tr>
                    <tr>
                        <td id="tdgrandtotal" runat="server" colspan="2">
                            <b>Grand Total</b>&nbsp;
                        </td>
                        <td id="tdgrandtotaltext" runat="server"  align="right">
                            &nbsp;<asp:TextBox ID="txtgrandtotal" runat="server" CssClass="DisableInputNumber" onKeyDown="return EnabledTabKey(this.id, event);"
                                Style="width: 100px;"></asp:TextBox>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
    </table>
    <table style="width: 96%;">
        <tr>
            <td align="center">
                <asp:Button ID="btnUpdate" Text="Update" runat="server" CssClass="button" OnClientClick="return validatemptyfield();"
                    OnClick="btnUpdate_Click" />
                &nbsp;
                <asp:Button ID="btnCancel" Text="Cancel" runat="server" CssClass="button" OnClick="btnCancel_Click" />
            </td>
        </tr>
    </table>
    <asp:GridView ID="grid" runat="server">
    </asp:GridView>
    <br />
    </form>
</body>
</html>

